Skip to main content

Java RESTful Engine Custom Processing Reference

As of RESTful Engine version 24.3+, we now offer the ability to perform custom processing on your generated document before it is marked as done and ready for delivery. You can find a sample implementation using the Apryse Java SDK here.

Requirements

In order to implement your own custom processing plugin for the RESTful Engine, you will need the following:

  • RESTful engine version 24.3+
  • A Reference to the FluentCustomProcessing library in your project's POM file The FluentCustomProcessing library contains the following:
  • IDocumentPostProcessor: This is the interface that you will implement
  • CustomDocument: This is the model used as the data transfer object between the RESTful engine and your defined custom plugin
  • CustomProcessingTestUtil Class: This class contains methods that will help you test your custom code before using it in the RESTful Engine.

Setting It Up

  1. Create a new maven project and adding the following reference to your POM file (if you don't already, make sure you have the windward-maven-repo repository in your POM file):

<repositories>
<repository>
<id>windward-maven-repo</id>
<name>windward-maven-repo</name>
<url>https://windward.mycloudrepo.io/public/repositories/windward-libs</url>
</repository>
<repositories>
.
.
.
<dependencies>
.
.
.
<dependency>
<groupId>com.windward</groupId>
<artifactId>FluentCustomProcessing</artifactId>
<version>LATEST</version>
</dependency>

The latest version number will match the latest release version of the RESTful engine found in the downloads page

  1. Once you have the FluentCustomProcessing added as a dependency for your project, create a new class that implements the IDocumentPostProcessor interface. Make sure to import the library into your file.
package CustomProcessor;

import FluentCustomProcessing.*;

public class CustomProcessor implements IDocumentPostProcessor {
}

The IDocumentPostProcessor only defines one method that you must implement:

CustomDocument process(CustomDocument document);

This is an method that takes in a CustomDocument object. These are the member variables in the CustomDocument model:

/*The generated report as a single file in the user specified format. If this is populated Pages will be null. */ 
private byte[] Data { get; set; }

/*The generated report as a distinct file per page in the user specified format. If this is populated Data will be null. This is produced by the image report generator and by the HTML report generator when it is in per page mode.*/
private byte[][] Pages { get; set; }

You can use the process method to do your own custom processing on the generated report's data before it is marked as complete. Whatever processing you do, make sure to return a CustomDocument.

Testing It

In the FluentCustomProcessing package we provide a class (CustomProcessingTestUtil) that has the following method:

public static CustomDocument getDocument(String path)

This method will return an object similar to the one we will use in the RESTful engine with your custom code. The method takes in the path for a docgen.complete file (the xml file for a generated report). In order to use this method, you must initially produce output from the base RESTful engine. Once you have done that, navigate to the directory where the RESTful engine stores output. The default directory is: {PATH_TO_TOMCAT}\webapps\App_Data\requests

Then find the {guid}.docgen.complete file, pass its absolute path into the getDocument() method and it will return a CustomDocument object for you to test with.

To use this method, instantiate the class and call the method:

CustomDocument customDoc = CustomProcessingTestUtil.getDocument("PATH_TO_.docgen.complete_FILE");
//Then you can test out your custom processing code on customDoc

Using the Custom Processing Plugin

After you have defined and tested your implementation of IDocumentPostProcessor, you are now ready to inject it and use it in your production RESTful Engine.

The first thing you need to do is compile your custom processor project into JAR file. Once you have the JAR, do the following in your RESTful engine's WindwardReports.properties file:

postProcessor=PATH_TO_JAR!PACKAGE_NAME.CLASS_NAME

Where:

  • PATH_TO_JAR is the path to the JAR file
  • PACKAGE_NAME is the package name of your custom processor class
  • CLASS_NAME is the name of your custom processor class

Then, start up your RESTful engine and it will now use your custom processing plugin to process the generated documents.